const express = require('express');
const webpack = require('webpack');
const open = require("open")
const webpackDevMiddleware = require('webpack-dev-middleware');

const app = express();
const config = require('./config/webpack.dev.js')();
const compiler = webpack(config);

// 告知 express 使用 webpack-dev-middleware，
// 以及将 webpack.config.js 配置文件作为基础配置。
app.use(webpackDevMiddleware(compiler, {
    publicPath: config.output.publicPath
}));

app.use(require("webpack-hot-middleware")(compiler));

const port = 3000

// 将文件 serve 到 port 3000。
app.listen(port, function () {
    open(`http://localhost:${port}`)
    console.log(`Example app listening on port ${port}!\n`);
});